package edu.pku.sei.act.taskStruct;
import java.util.AbstractSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.dom4j.Attribute;
import org.dom4j.Element;

public class State extends Ident{
	
	public Set<String>  preTranses;
	public Set<String>  postTranses;
	
	public void addAttrisAndEles(Element element)
	{
		addAttributes(element);
		Element ele;
		ele = element.addElement(TagNames.PRE_TRANSES);
		for(String transId: preTranses)
		{
			Element e;
			e = ele.addElement(TagNames.TRANS_ID);
			e.addText(transId);
		}
		ele = element.addElement(TagNames.POST_TRANSES);
		for(String transId: postTranses)
		{
			Element e;
			e = ele.addElement(TagNames.TRANS_ID);
			e.addText(transId);
		}
	}
	
	public State(String id, String name)
	{
		super(id, name);
		setDefaultVal();	
	}
	
	public State()
	{
		super();
		setDefaultVal();
	}
	
	private void setDefaultVal()
	{
		preTranses = new TreeSet<String>();
		postTranses = new TreeSet<String>();
	}
	
	public State(Element element)
	{
		super();
		setIdAndName(element);
		setDefaultVal();
		Element ele = element.element(TagNames.PRE_TRANSES);
		
		if(ele != null)
		{
			List<Element> list = ele.elements(TagNames.TRANS_ID);
			for(Element e: list)
			{
				String pretrans = e.getTextTrim();
				if(!"".equals(pretrans))
					preTranses.add(pretrans);
			}
		}
		ele = element.element(TagNames.POST_TRANSES);
		if(ele != null)
		{
			List<Element> list = ele.elements(TagNames.TRANS_ID);
			for(Element e: list)
			{	
				String posttrans = e.getTextTrim();
				if(!"".equals(posttrans))
					postTranses.add(posttrans);
			}
		}
	}
	
	public Set<String> getPreTranses()
	{
		//return new TreeSet<String>(preTranses);
		return preTranses;
	}
	
	public Set<String> getPostTranses()
	{
		//return new TreeSet<String>(postTranses);
		return postTranses;
	}
	
}
